package com.dindang.maintenance.mvp.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.jess.arms.base.BaseActivity;
import com.jess.arms.di.component.AppComponent;
import com.jess.arms.utils.ArmsUtils;

import com.dindang.maintenance.di.component.DaggerMaintainManagementComponent;
import com.dindang.maintenance.di.module.MaintainManagementModule;
import com.dindang.maintenance.mvp.contract.MaintainManagementContract;
import com.dindang.maintenance.mvp.presenter.MaintainManagementPresenter;

import com.dindang.maintenance.R;
import com.longxi.gamer_base.widget.EmptyLayout;


import in.srain.cube.views.ptr2.PtrClassicFrameLayout;

import static com.jess.arms.utils.Preconditions.checkNotNull;

@Route(path = "/maintenance/activity/MaintainManagementActivity")
public class MaintainManagementActivity extends BaseActivity<MaintainManagementPresenter> implements MaintainManagementContract.View {

    ImageView mIvBack;
    TextView mTvTitle;
    ImageView mIvAdvanceSearch;
    PtrClassicFrameLayout mPtrclassicframelayout;
    RecyclerView mRecyclerview;
    EmptyLayout mEmptyLayout;
    EditText mEtSearch;

    @Override
    public void setupActivityComponent(@NonNull AppComponent appComponent) {
        DaggerMaintainManagementComponent //如找不到该类,请编译一下项目
            .builder()
            .appComponent(appComponent)
            .maintainManagementModule(new MaintainManagementModule(this))
            .build()
            .inject(this);
    }

    @Override
    public int initView(@Nullable Bundle savedInstanceState) {
        return R.layout.maintenance_activity_maintain_management; //如果你不需要框架帮你设置 setContentView(id) 需要自行设置,请返回 0
    }

    @Override
    public void initData(@Nullable Bundle savedInstanceState) {
        mIvBack = findViewById(R.id.maintenance_iv_back);
        mTvTitle = findViewById(R.id.maintenance_tv_title);
        mIvAdvanceSearch = findViewById(R.id.maintenance_iv_right);
        mIvAdvanceSearch.setImageResource(R.mipmap.maintenance_ic_advance_search);
        mIvAdvanceSearch.setVisibility(View.VISIBLE);
        mPtrclassicframelayout = findViewById(R.id.maintenance_ptrclassicframelayout);
        mRecyclerview = findViewById(R.id.maintenance_recyclerview);
        mEmptyLayout = findViewById(R.id.maintenance_emptyLayout);
        mEtSearch = findViewById(R.id.maintenance_et_search);

        mTvTitle.setText("维修管理");
        mTvTitle.setOnClickListener(v -> finish());
        mIvBack.setOnClickListener(v -> finish());
        mIvAdvanceSearch.setOnClickListener(v -> mPresenter.dialogAdvanceSearch());

        mPresenter.init();
    }

    @Override
    public void showLoading() {

    }

    @Override
    public void hideLoading() {

    }

    @Override
    public void showMessage(@NonNull String message) {
        checkNotNull(message);
        ArmsUtils.snackbarText(message);
    }

    @Override
    public void launchActivity(@NonNull Intent intent) {
        checkNotNull(intent);
        ArmsUtils.startActivity(intent);
    }

    @Override
    public void killMyself() {
        finish();
    }

    @Override
    public PtrClassicFrameLayout getPtrclassicframelayout() {
        return mPtrclassicframelayout;
    }

    @Override
    public RecyclerView getRecyclerview() {
        return mRecyclerview;
    }

    @Override
    public EmptyLayout getEmptyLayout() {
        return mEmptyLayout;
    }

    @Override
    public EditText getEtSearch() {
        return mEtSearch;
    }

    @Override
    public BaseActivity getActivity() {
        return this;
    }
}
